<template>
  <div>
    <el-card style="max-width: 90vw">
      <el-form label-position="right" label-width="auto" :model="form" ref="formRef" style="max-width: 600px">
        <h2 class="card-header">
          <span>教师毕业设计出题</span>
        </h2>
        <el-form-item label="题目名称" prop="isNull">
          <el-input v-model="form.titleName" />
        </el-form-item>
        <el-form-item label="题目来源" prop="isNull">
          <el-input v-model="form.titleSource" />
        </el-form-item>
        <el-form-item label="功能要求" prop="isNull">
          <el-input v-model="form.titleRequirement" />
        </el-form-item>
        <el-form-item label="技术要求" prop="isNull">
          <el-input v-model="form.technicalRequirement" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">提交</el-button>
          <el-button @click="clean">清空</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "Notice",
  data() {
    return {
      form: {
        titleName: '',
        titleSource: '',
        titleRequirement: '',
        technicalRequirement: '',
        teacherId: ''
      },
      rules: {
        isNull: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ]
      }
    }
  },
  created() {

  },
  methods: {
    onSubmit() {
      let user = JSON.parse(sessionStorage.getItem('user'))
      console.log(user.id)
      this.form.teacherId = user.id
      this.$request.post('/graduation/topic', this.form).then(res => {
        if (res.code === 200) {
          this.$message.success('提交成功')
        } else {
          this.$message.error(res.msg)
        }
      }).catch(err => {
        this.$message.error('提交错误')
      })
      this.clean()
    },
    clean() {
      this.form = {
        titleName: '',
        titleSource: '',
        titleRequirement: '',
        technicalRequirement: '',
        teacherId: ''
      }
    }
  }
}
</script>

<style scoped>
.card-header {
  margin-bottom: 20px;
}
</style>
